package com.onlinelibrary.controller;


import com.onlinelibrary.pojo.Book;
import com.onlinelibrary.result.Result;
import com.onlinelibrary.service.BookService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@RestController
@RequestMapping("/book")
public class BookController {

    private final BookService bookService;

    @GetMapping ("/list")
    Result list(){
        return bookService.list();
    }

    @PostMapping("/getTopImg")
    Result getTopImg(){
        return bookService.getTopImg();
    }

    @PostMapping("getBook")
    Result getBook(@RequestBody Book book){
        return bookService.getBook(book);
    }

    @PostMapping("/addBook")
    Result addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }

    @PostMapping("/updateCoverImage")
    Result updateCoverImage(@RequestParam("file") MultipartFile file, @RequestParam("isbn") String isbn){
        return bookService.updateCoverImage(file,isbn);
    }

    @PostMapping("/updateBook")
    Result updateBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }


    @PostMapping("/getTableData")
    Result getTableData(@RequestBody Book book){
        return bookService.getTableData(book);
    }


    @PostMapping("/deleteBook")
    Result deleteBook(@RequestBody Book book){
        return bookService.deleteBook(book);
    }

    @PostMapping("/getBooks")
    Result getBooks(@RequestBody Book book){
        return bookService.getBooks(book);
    }

    // /getBooksByBookName
    @PostMapping("/getBooksByBookName")
    Result getBooksByBookName(@RequestBody Book book){
        return bookService.getBooksByBookName(book);
    }

}
